/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.lidovky.articles.articlesData.pesta;

import cz.mzk.lidovky.articles.articlesData.CsvParser;
import java.text.Normalizer;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author x211800
 */
public class Columns {

    protected static final char CSV_TEXT_SEPARATOR = '\"';
    protected static final String EMPTY_STRING = "";
    protected static final String WHITESPACE = " ";
    protected static final Logger logger = Logger.getLogger(CsvParser.class.getName());
    protected static final char CSV_FIELD_SEPARATOR = '\t';
    protected static final String SLASH = "/";
    protected static final String SEMICOLON = ";";
    protected static final String COMA = ",";
    protected static final String DOT = ".";



    protected static boolean stringToInteger(String record) {
        try {
            int issue = Integer.parseInt(record);
        } catch (NumberFormatException nfe) {
            return false;
        }
        return true;
    }

    protected static String removeTextDelimits(String string) {
        if ("".equals(string)) {
            return null;
        }
        int size = string.length();
        //System.out.println("size: " + size);
        if (string.charAt(0) != CSV_TEXT_SEPARATOR || string.charAt(size - 1) != CSV_TEXT_SEPARATOR) {
            logger.log(Level.SEVERE, "String ''{0}'' not quoted with ''{1}''", new Object[]{string, CSV_TEXT_SEPARATOR});
            return null;
        }
        return string.substring(1, size - 1);
    }

    /**
     *
     * @param string
     * @return for text returns "text" (if CSV_TEXT_SEPARATOR is '"')
     * for {@code string == null} returns null, for {@code string == ""} returns ""
     */
    protected static String addTextDelimits(String string) {
        if (string == null) {
            return null;
        }
        if (string.equals(EMPTY_STRING)) {
            return EMPTY_STRING;
        }
        StringBuilder builder = new StringBuilder(3);
        builder.append(CSV_TEXT_SEPARATOR);
        builder.append(string);
        builder.append(CSV_TEXT_SEPARATOR);
        return builder.toString();
    }

    protected static String removeDiacritics(String s) {
        return Normalizer.normalize(s, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
    }

    protected static String removeWhiteSpaces(String string) {
        StringBuffer bufferedString = new StringBuffer(string);

        for (int i = 0; i < bufferedString.length(); i++) {

            if (bufferedString.substring(i, i + 1).equals(String.valueOf(WHITESPACE))) {
                bufferedString.delete(i, i + 1);
            }
        }
        return bufferedString.toString();
    }


}
